package dht.async;

import java.util.concurrent.Executor; /**
 * File:   Communicator.java
 * Author: Gvennet
 */

/** todo write javadoc */
public class Communicator
{

    protected Communicator(Executor executor)
    {
        this.executor = executor;
    }

    private Executor executor;

    protected void sendMessage(Message m)
    {
        executor.execute(new Task(m));
    }


    private class Task implements Runnable
    {

        private Task(Message message)
        {
            this.message = message;
        }

        private final Message message;

        @Override
        public void run()
        {


            Node s = message.getSender();
            Node r = message.getReceiver();

            r.receive(message);
        }


    }


}
